﻿
using System;
using System.Threading.Tasks;

namespace MiniErp.Common.Cache
{
    /// <summary>
    /// 缓存接口
    /// </summary>
    public interface ICache
    {
      

        /// <summary>
        /// 用于在 key 存在时删除 key
        /// </summary>
        /// <param name="key">键</param>
        /// <returns></returns>
        Task<long> DelAsync(string type, params string[] key);


        /// <summary>
        /// 检查给定 key 是否存在
        /// </summary>
        /// <param name="key">键</param>
        /// <returns></returns>
        Task<bool> ExistsAsync(string type, string key);


        /// <summary>
        /// 获取指定 key 的值
        /// </summary>
        /// <param name="key">键</param>
        /// <returns></returns>
        Task<string> GetAsync(string type, string key);
       

        /// <summary>
        /// 获取指定 key 的值
        /// </summary>
        /// <typeparam name="T">byte[] 或其他类型</typeparam>
        /// <param name="key">键</param>
        /// <returns></returns>
        Task<T> GetAsync<T>(string type, string key);

        /// <summary>
        /// 根据匹配符获取指定 key 的值
        /// </summary>
        /// <param name="wildcard">匹配符</param>
        /// <returns></returns>
        Task<string[]> GetAsyncByWildCard(string wildcard);



        /// <summary>
        /// 设置指定 key 的值，所有写入参数object都支持string | byte[] | 数值 | 对象
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="value">值</param>
        /// <returns></returns>
        Task<bool> SetAsync(string type, string key, object value);

        /// <summary>
        /// 设置指定 key 的值，所有写入参数object都支持string | byte[] | 数值 | 对象
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="value">值</param>
        /// <param name="expire">有效期 秒</param>
        /// <returns></returns>
        Task<bool> SetAsync(string type, string key, object value, TimeSpan expire);

        /// <summary>
        /// 设置指定 key 的值到Set（值自动去重），所有写入参数object都支持string | byte[] | 数值 | 对象
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="value">值</param>
        /// <returns>等于0则添加值失败</returns>
        Task<long> SAddAsync(string type, string key, object value);

        /// <summary>
        /// 设置指定 key 的值到Set（值自动去重），所有写入参数object都支持string | byte[] | 数值 | 对象
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="value">值</param>
        /// <param name="expire">有效期 秒</param>
        /// <returns>等于0则添加值失败</returns>
        Task<long> SAddAsync(string type, string key, object value, TimeSpan expire);

    }
}
